package com.faker.dba.service.impl;

import cn.hutool.core.lang.UUID;
import com.faker.dba.filter.MobileAuthFilter;
import com.faker.dba.model.dto.LoginDto;
import com.faker.dba.service.UserCenterService;
import com.faker.dba.wrapper.AesWrapMapper;
import com.faker.dba.wrapper.Wrapper;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.concurrent.ConcurrentHashMap;

/**
 * <p>
 * 移动端用户表 服务实现类
 * </p>
 *
 * @author anlinxi
 * @since 2022-08-21
 */
@Service
public class UserCenterServiceImpl implements UserCenterService {

    @ApiModelProperty("定义的登录用户名")
    @Value("${login.username}")
    private String username;

    @ApiModelProperty("定义的登录密码")
    @Value("${login.password}")
    private String password;



    /**
     * 登录方法
     *
     * @param params 登录参数
     * @return 返回结果
     */
    @Override
    public Wrapper login(LoginDto params) {
        //todo 以后改成动态的
        if (!"ngge".equalsIgnoreCase(params.getVercode())) {
            return AesWrapMapper.error("验证码错误!");
        }
        if (!username.equals(params.getUsername())) {
            return AesWrapMapper.error("用户名或密码错误!");
        }
        if (!password.equals(params.getPassword())) {
            return AesWrapMapper.error("用户名或密码错误!");
        }
        String token = UUID.randomUUID().toString().replace("-", "");
        MobileAuthFilter.userTokenMap.put(params.getUsername(), token);
        return AesWrapMapper.ok(token);
    }
}
